package com.tsc.dateinfo;

import java.util.ArrayList;

import com.tsc.dateinfo.data.IData;
import com.tsc.dateinfo.data.ParseCouponMoa;

public class ServerMain implements Runnable{
	
	public static void main(String[] args) {
		ServerMain server = new ServerMain();
		Thread thread = new Thread(server);
		thread.start();
		
	}
	
	private ParseCouponMoa couponMoa;
	private DatabaseHelper dbHelper;
	private boolean isRunning = false;
	public ServerMain()
	{
		couponMoa = new ParseCouponMoa();
		dbHelper = new DatabaseHelper();
		
		couponMoa.setDBHelper(dbHelper);
	}
	
	public void stop()
	{
		isRunning = false;
	}

	public void run() {
		// TODO Auto-generated method stub
		isRunning  = true;
		while(isRunning) {
			ServerLog.log("info", "server thread started!");
			couponMoa.parse();
			ServerLog.log("info", "success to get items.");
			ArrayList<IData> listData = couponMoa.getData();
			ServerLog.log("debug", "success get data");
			
			
			
			ServerLog.log("debug", "success insert to db");
			ServerLog.log("info", "refreshed server db. " + listData.size() + "items inserted.");
			try {Thread.sleep(30*60*1000);}catch(Exception e){}
		}
	}
}
